<?php

class Admin extends CI_Controller {

	function index()
	{
		$this->load->helper(array('form', 'url'));

		$this->load->library('form_validation');

		$this->form_validation->set_message('required', 'El campo %s es obligatorio.');
		
		$this->form_validation->set_rules('carnet', 'Carnet', 'trim|required|min_length[7]|callback_username_check');
		$this->form_validation->set_rules('password', 'Password', 'trim|required|md5');
		
		
		

		if ($this->form_validation->run() == FALSE)
		{
			$this->load->view('mylogin');
		}
		else
		{
			$sess_array = array(
               'carnet' => 'vm07003'
            );
            $this -> session -> set_userdata('logged_in', $sess_array);
			
			$this->load->view('loginsuccess');
		}
	}

	function username_check($str)
	{
		if ($str == 'test')
		{
			$this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
	
}
?>